<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head><title>Programming in Lua : 1.2</title>
<link rel="stylesheet" type="text/css" href="pil.css">
</head>
<body>
<p class="warning">
<A HREF="contents.html"><IMG TITLE="Programming in Lua (first edition)" SRC="capa.jpg" ALT="" ALIGN="left"></A>This first edition was written for Lua 5.0. While still largely relevant for later versions, there are some differences.<BR>The third edition targets Lua 5.2 and is available at <A HREF="http://www.amazon.com/exec/obidos/ASIN/859037985X/theprogrammil3-20">Amazon</A> and other bookstores.<BR>By buying the book, you also help to <A HREF="../donations.html">support the Lua project</A>.
</p>
<table width="100%" class="nav">
<tr>
<td width="10%" align="left"><a href="1.1.html"><img border="0" src="left.png" alt="Previous"></a></td>
<td width="80%" align="center"><a href="contents.html"><font face="Helvetica,Arial,sanserif">
<font color="gray">Programming in </font><font color="blue"> Lua</font>
</font></a></td>
<td width="10%" align="right"><a href="1.3.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
<tr>
<td width="10%" align="left"></td>
<td width="80%" align="center"><a href="contents.html#P1">Part I. The Language</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="contents.html#1">Chapter 1. Getting Started</a></td>
<td width="10%" align="right"></td></tr>
</table>
<hr/>
<p><h2>1.2 &ndash; Global Variables</h2>

<p>

<p>Global variables do not need declarations.
You simply assign a value to a global
variable to create it.
It is not an error to access a non-initialized variable;
you just get the special value <B>nil</B> as the result:
<pre>
    print(b)  --> nil
    b = 10
    print(b)  --> 10
</pre>

<p>Usually you do not need to delete global variables;
if your variable is going to have a short life,
you should use a local variable.
But, if you need to delete a global variable,
just assign <B>nil</B> to it:
<pre>
    b = nil
    print(b)  --> nil
</pre>
After that, it is as if the variable had never been used.
In other words, a global variable is <em>existent</em> if (and only if)
it has a non-nil value.

<hr/>
<table width="100%" class="nav">
<tr valign="top">
<td width="90%" align="left">
<small>
  Copyright &copy; 2003&ndash;2004 Roberto Ierusalimschy.  All rights reserved.
</small>
</td>
<td width="10%" align="right"><a href="1.3.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
</table>


</body></html>

